package com.pan.basic;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2021/11/27
 */
public class TryCatchFinally {


    public static void tryFinally(){
        System.out.println("start"+"tryFinally");
        int i=0;
        try {
            System.out.println(i++);
        }finally {
            i=3;
            System.out.println(i);
        }
        System.out.println(i);
        System.out.println("end"+"tryFinally");
    }

    public static void tryFinallyException(){
        System.out.println("start"+"tryFinallyException");
        int i=0;
        try {
            System.out.println(i++);
            if(10!=i){
                throw new RuntimeException("会报错");
            }

        }finally {
            i=3;
            System.out.println(i);
        }
        System.out.println(i);
        System.out.println("end"+"tryFinallyException");
    }

    public static void tryCatchFinallyException(){
        System.out.println("start"+"tryCatchFinallyException");
        int i=0;
        try {
            System.out.println(i++);
            if(10!=i){
                throw new RuntimeException("会报错");
            }

        }catch(Exception e){
             i=4;
            System.out.println(i);
        }finally {
            i=3;
            System.out.println(i);
        }
        System.out.println(i);
        System.out.println("end"+"tryCatchFinallyException");
    }

    public static int tryCath(){
        System.out.println("start"+"tryCath");
        int i=0;
        try {
            System.out.println(i++);
            return i;
        }catch(Exception e){
            i=4;
            System.out.println(i);
            return i;
        }
    }

    public static int tryFinally1(){
        System.out.println("start"+"tryFinally1");
        int i=0;
        try {
            System.out.println(i++);
            return i;
        }finally {
            i=4;
            System.out.println(i);
            return i;
        }
    }

    public static int tryFinally2(){
        System.out.println("start"+"tryFinally2");
        int i=0;
        try {
            System.out.println(i++);
            return i;
        }finally {
            i=4;
            System.out.println(i);
        }
    }

    public static int tryCathFainlly1(){
        System.out.println("start"+"tryCathFainlly1");
        int i=0;
        try {
            System.out.println(i++);
            return i;
        }catch(Exception e){
            i=4;
            System.out.println(i);
            return i;
        }finally {
            i=5;
            System.out.println(i);
        }
    }

    public static int tryCathFainlly2(){
        System.out.println("start"+"tryCathFainlly2");
        int i=0;
        try {
            System.out.println(i++);
            return i;
        }catch(Exception e){
            i=4;
            System.out.println(i);
            return i;
        }finally {
            i=5;
            System.out.println(i);
            return i;
        }
    }

    public static int tryCathFainlly3(){
        System.out.println("start"+"tryCathFainlly3");
        int i=0;
        try {
            System.out.println(i++);
            if(i!=10){
                throw new RuntimeException("tryCathFainlly3");
            }
            return i;
        }catch(Exception e){
            i=4;
            System.out.println(i);
            return i;
        }finally {
            i=5;
            System.out.println(i);
            return i;
        }
    }

    public static void main(String[] args) {
        tryFinally();
        try {
            tryFinallyException();
        }catch (Exception e){
            System.out.println("tryFinallyException");
        }
        try {
            tryCatchFinallyException();
        }catch (Exception e){
            System.out.println("tryCatchFinallyException");
        }
        int i=tryCath();
        System.out.println("tryCath()"+i);
        int l = tryFinally1();
        System.out.println("tryFinally1()"+l);
        int m = tryFinally2();
        System.out.println("tryFinally2()"+m);
        int j = tryCathFainlly1();
        System.out.println("tryCathFainlly1()"+j);
        int k = tryCathFainlly2();
        System.out.println("tryCathFainlly2()"+k);
        try{
            int n = tryCathFainlly3();
            System.out.println("tryCathFainlly3"+n);
        }catch (Exception e){
            System.out.println("tryCathFainlly3"+e.getMessage());

        }
        

    }



}
